package com.zat.mes.andrmes.dofun.main.adapter

import android.content.ActivityNotFoundException
import android.content.Intent
import android.util.Log
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.HomeBtnBean
import com.zat.mes.andrmes.dofun.main.BindMachineActivity
import com.zat.mes.andrmes.dofun.qualitytest.QualityHistActivity
import com.zat.mes.andrmes.dofun.qualitytest.QualityPlanActivity
import com.zat.mes.andrmes.dofun.qualitytest.QualityRecordActivity
import com.zat.mes.andrmes.dofun.system.ClockInActivity
import com.zat.mes.andrmes.dofun.system.ClockInReadActivity
import com.zat.mes.andrmes.dofun.work.*
import com.zat.mes.andrmes.event.QrcodeEventMessage
import com.zat.mes.andrmes.global.CompanionCode
import com.zat.mes.andrmes.utils.HttpsKitUtils
import org.greenrobot.eventbus.EventBus

/**
 * @author zy
 * @date :2020-02-13 16:50
 * @description:首页按钮adapter
 */
class HomeBtnAdapter(layoutResId: Int) :
    BaseQuickAdapter<HomeBtnBean, BaseViewHolder>(layoutResId) {


    override fun convert(helper: BaseViewHolder, item: HomeBtnBean) {

        helper.setText(R.id.tvItemBtnHome, item?.menuname)
        item?.iconurl = HttpsKitUtils.replaceHttpsUrl(item?.iconurl)
        Glide.with(context).load(item?.iconurl)
            .into(helper.getView(R.id.ivItemBtnHome))

        helper.itemView.setOnClickListener {
            //测试
            if ("sign".equals(item?.pageurl)) {
                //签到
                startMyActivity(Intent(context, ClockInActivity::class.java))
            } else if ("signCheck".equals(item?.pageurl)) {
//                签到审核
                startMyActivity(Intent(context, ClockInReadActivity::class.java))
            } else if ("qrCode".equals(item?.pageurl)) {
                //扫码
                startMyActivity(Intent(context,BindMachineActivity::class.java))
//                EventBus.getDefault().post(QrcodeEventMessage(CompanionCode.REQUEST_EMP_CH_QR_CODE))
            } else if ("productPlan".equals(item?.pageurl)) {
                //生产计划
                startMyActivity(Intent(context, DayProducePlanAndMaterialUsedActivity::class.java))
            } else if ("workPiece".equals(item?.pageurl)) {
                //做工计件
                startMyActivity(Intent(context, DayWorkScanActivity::class.java))
            } else if ("salary".equals(item?.pageurl)) {
                //工资查询
                startMyActivity(Intent(context, WorkWageActivity::class.java))
            } else if ("qcPlan".equals(item?.pageurl)) {
                //质检计划
                startMyActivity(Intent(context, QualityPlanActivity::class.java))
            } else if ("qcRecord".equals(item?.pageurl)) {
                //质检
                EventBus.getDefault()
                    .post(QrcodeEventMessage(CompanionCode.REQUEST_QC_PLAN_QR_CODE))
            } else if ("onsite".equals(item?.pageurl)) {
                //巡检
                EventBus.getDefault()
                    .post(QrcodeEventMessage(CompanionCode.REQUEST_ON_SITE_QR_CODE))
            } else if ("onsiteRecord".equals(item?.pageurl)) {
                //巡检处理
                startMyActivity(Intent(context, QualityRecordActivity::class.java))
            } else if ("workList".equals(item?.pageurl)) {
                //做工记录
                startMyActivity(Intent(context, DayWorkRecordActivity::class.java))
            } else if ("qchist".equals(item?.pageurl)) {
                //质检记录
                startMyActivity(Intent(context, QualityHistActivity::class.java))
            } else if ("getPack".equals(item?.pageurl)) {
                //领取裁片包
                startMyActivity(Intent(context, GetPackActivity::class.java))
            } else if ("packQty".equals(item?.pageurl)) {
                //修改裁片包数量
                startMyActivity(Intent(context, UpdatePackQtyActivity::class.java))
            } else if ("outSourceIn".equals(item?.pageurl)) {
                //外协入库
                startMyActivity(Intent(context, OutSourceInHouseActivity::class.java))
            }else if("yarnIn".equals(item?.pageurl)){
                //领纱
                startMyActivity(Intent(context,YarnInActivity::class.java));
            }else if("yarnUn".equals(item?.pageurl)){
                //退纱
                startMyActivity(Intent(context,YarnUnActivity::class.java))
            }else if("badFlat".equals(item?.pageurl)){
                //废片
                startMyActivity(Intent(context,BadFlatActivity::class.java))
            }else if("disassemble".equals(item?.pageurl)){
                //拆解单
                startMyActivity(Intent(context,DisassembleActivity::class.java))
            }else if("inhouse".equals(item?.pageurl)){
                //入库
                startMyActivity(Intent(context,InHouseActivity::class.java))
            }else if("outhouse".equals(item?.pageurl)){
                //出库
                startMyActivity(Intent(context,OutHouseActivity::class.java))
            }else if("bindClothes".equals(item?.pageurl)){
                //绑定衣服
                startMyActivity(Intent(context,BindClothesActivity::class.java))
            }else if("macCheck".equals(item?.pageurl)){
                //机器检查
                startMyActivity(Intent(context,MacCheckAddActivity::class.java))
            }else if("macDayCare".equals(item?.pageurl)){
                //日机维护
                startMyActivity(Intent(context,MacDayCareAddActivity::class.java))
            }else if("macWeekCare".equals(item?.pageurl)){
                //周机维护
                startMyActivity(Intent(context,MacWeekCareAddActivity::class.java))

            }else if("packing".equals(item?.pageurl)){
                //装箱
                startMyActivity(Intent(context,PackingActivity::class.java))
            }else if("styleFile".equals(item?.pageurl)){
                //款式资料
                startMyActivity(Intent(context,StyleExtraFileActivity::class.java))
            }else if ("machineWarn".equals(item?.pageurl)){
                startMyActivity(Intent(context,MachineWarnActivity::class.java))
            }else if("daomao".equals(item?.pageurl)){
                startMyActivity(Intent(context,UpdateDmQtyActivity::class.java))
            }else if("getBomNotifi".equals(item?.pageurl)){
                //领料通知单
                startMyActivity(Intent(context,GetBomNotifiActivity::class.java))
            }else if ("motorWorkRecord".equals(item?.pageurl)){
                //电机做工记录
                startMyActivity(Intent(context, MotorWorkRecordActivity::class.java))

            }
        }


    }

    fun startMyActivity(intent: Intent) {
        try {
            context.startActivity(intent)
        } catch (e: ActivityNotFoundException) {
            Log.e("activity", e.toString())
        }

    }
}